package com.gjzhao.fmmall.config.myfilter;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description: 配置过滤器
 * @Author: gjzhao
 * @Date Created in 2022-02-17 9:38 下午
 */
@Configuration
public class FilterConfig {

    private Logger logger = LoggerFactory.getLogger(getClass());

    @Bean
    public RouteLocator routeLocator(RouteLocatorBuilder builder) {

        logger.info("-----初始化过滤器-----");

        RouteLocator routeLocator = builder.routes()
                                           .route(
                                               r -> r.path("/ordersHystrix/**") // 断言
                                                    .filters(f -> f.filters(new MyFilter())) // 自定义过滤器
                                                    .uri("http://localhost:8083") //服务地址
                                    ).build();
        return routeLocator;
    }

}
